package com.algrithom.pointer;

/**
 * 11. 盛最多水的容器
 * 
 * @author think
 */
public class Solution1 {
    
    public static void main(String[] args){
        int[] height = new int[]{1,8,6,2,5,4,8,3,7};
        Solution1 solution1 = new Solution1();
        System.out.println(solution1.maxArea(height));
    }
    
    public int maxArea(int[] height){
        int left = 0;
        int right = height.length - 1;
        int area = 0;
        int resultArea = 0;
        while (left < right) {
            area = (right - left) * Math.min(height[left],height[right]);
            if (resultArea < area) {
                resultArea = area;
            }
            if (height[left] <= height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return resultArea;
    }
}
